<?php

/**
 * This is the model class for table "sys_reward".
 *
 * The followings are the available columns in table 'sys_reward':
 * @property string $reward_id
 * @property string $reward_reward_category_id
 * @property string $reward_cond_node_left
 * @property string $reward_cond_node_right
 * @property string $reward_bonus
 * @property string $reward_bonus_value
 * @property string $reward_is_active
 *
 * The followings are the available model relations:
 * @property SysRewardCategory $rewardRewardCategory
 * @property SysRewardLog[] $sysRewardLogs
 */
class sys_reward extends CActiveRecord {

    /**
     * Returns the static model of the specified AR class.
     * @return sys_reward the static model class
     */
    public static function model($className=__CLASS__) {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return 'sys_reward';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('reward_reward_category_id, reward_cond_node_left, reward_cond_node_right', 'length', 'max' => 10),
            array('reward_bonus, reward_bonus_value', 'length', 'max' => 255),
            array('reward_is_active', 'length', 'max' => 1),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('reward_id, reward_reward_category_id, reward_cond_node_left, reward_cond_node_right, reward_bonus, reward_bonus_value, reward_is_active', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'rel_reward_to_reward_category' => array(self::BELONGS_TO, 'sys_reward_category', 'reward_reward_category_id'),
            'rel_reward_to_reward_log' => array(self::HAS_MANY, 'sys_reward_log', 'reward_log_reward_id'),
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'reward_id' => 'Reward',
            'reward_reward_category_id' => 'Reward Category',
            'reward_cond_node_left' => 'Reward Cond Node Left',
            'reward_cond_node_right' => 'Reward Cond Node Right',
            'reward_bonus' => 'Reward Bonus',
            'reward_bonus_value' => 'Reward Bonus Value',
            'reward_is_active' => 'Reward Is Active',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search() {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('reward_id', $this->reward_id, true);
        $criteria->compare('reward_reward_category_id', $this->reward_reward_category_id, true);
        $criteria->compare('reward_cond_node_left', $this->reward_cond_node_left, true);
        $criteria->compare('reward_cond_node_right', $this->reward_cond_node_right, true);
        $criteria->compare('reward_bonus', $this->reward_bonus, true);
        $criteria->compare('reward_bonus_value', $this->reward_bonus_value, true);
        $criteria->compare('reward_is_active', $this->reward_is_active, true);

        return new CActiveDataProvider($this, array(
            'criteria' => $criteria,
        ));
    }

}